package com.banmoon.algorithm.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Question1380 {

    public static void main(String[] args) {
        int[][] matrix = {{3,7,8}, {9,11,13}, {15,16,17}};
        System.out.println(luckyNumbers(matrix));
    }

    public static List<Integer> luckyNumbers (int[][] matrix) {
        int[] xArr = new int[matrix.length];// 记录每一行中最小的数

        for (int i = 0; i < matrix.length; i++) {
            xArr[i] = 0;
            for (int j = 1; j < matrix[i].length; j++) {
                if(matrix[i][xArr[i]] > matrix[i][j]){
                    xArr[i] = j;
                }
            }
        }

        int max = 0;
        List<Integer> list = new ArrayList<>();
        A: for (int i = 0; i < xArr.length; i++) {
            int minIndex = xArr[i];
            max = matrix[i][minIndex];
            for (int j = 0; j < xArr.length; j++) {
                if(max<matrix[j][minIndex])
                    continue A;
            }
            list.add(max);
        }
        return list;
    }

}
